home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODFDev / ODF / Found / FWMemory / FWMemMgr.cpp < prev    next >
Encoding:
Text File  |  1996-09-17  |  5.1 KB  |  199 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWMemMgr.cpp
  4. //    Release Version:    $ ODF 2 $
  5. //
  6. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "FWFound.hpp"
  11.  
  12. #ifndef FWPRIDEB_H
  13. #include "FWPriDeb.h"
  14. #endif
  15.  
  16. #ifndef   FWMEMMGR_H
  17. #include "FWMemMgr.h"
  18. #endif
  19.  
  20. #ifndef FWEXCDEF_H
  21. #include "FWExcDef.h"
  22. #endif
  23.  
  24. #ifndef FWODEXCE_H
  25. #include "FWODExce.h"
  26. #endif
  27.  
  28. #ifndef FWMEMHLP_H
  29. #include "FWMemHlp.h"
  30. #endif
  31.  
  32. #ifndef FWNEW_H
  33. #include "FWNew.h"
  34. #endif
  35.  
  36. #if defined(FW_BUILD_MAC) && !defined(__OSUTILS__)
  37. #include <OSUtils.h>
  38. #endif
  39.  
  40. #if defined(FW_BUILD_MAC) && !defined(__MEMORY__)
  41. #include <Memory.h>
  42. #endif
  43.  
  44. #if defined(FW_BUILD_WIN) && !defined(_INC_WINDOWS)
  45. #include <Windows.h>
  46. #endif
  47.  
  48. #if defined(FW_BUILD_WIN) && !defined(_INC_WINDOWSX)
  49. #include <WindowsX.h>
  50. #endif
  51.  
  52. #if !defined(FW_qUsePlatformAlloc) && !defined(FW_qUseCRuntimeAlloc)
  53.  
  54. #ifdef FW_BUILD_WIN
  55. #include <MMStubs.h>
  56. #endif
  57.  
  58. #ifdef FW_BUILD_MAC
  59. #include <MemMgr.h>
  60. #endif
  61.  
  62. #endif
  63.  
  64. #include <string.h>
  65.  
  66. #if defined(__SC__) && defined(FW_BUILD_WIN)
  67.  
  68. #if !defined(__LIMITS_H)
  69. #include <limits.h>
  70. #endif
  71.  
  72. #if !defined(__HUGEPTR_H) && defined(FW_BUILD_WIN16)
  73. #include <hugeptr.h>
  74. #endif
  75.  
  76. #endif
  77.  
  78. #ifdef FW_BUILD_MAC
  79. #pragma segment FWMemory
  80. #endif
  81.  
  82. //========================================================================================
  83. // CLASS FW_CMemoryManager
  84. //========================================================================================
  85.  
  86. //----------------------------------------------------------------------------------------
  87. // FW_CMemoryManager::DefaultNewHandler
  88. //----------------------------------------------------------------------------------------
  89.  
  90. void FW_CMemoryManager::DefaultNewHandler()
  91. {
  92.     FW_Failure(FW_xMemoryExhausted);
  93. }
  94.  
  95. //----------------------------------------------------------------------------------------
  96. // FW_CMemoryManager::AllocateBlock - Allocate a non-relocatable block of fMemory.
  97. //----------------------------------------------------------------------------------------
  98. void* FW_CMemoryManager::AllocateBlock(unsigned long bytesRequested)
  99. {
  100.     void* aBlock = FW_PrivMemoryManager_AllocateBlock(bytesRequested);
  101.  
  102.     if (aBlock == 0)
  103.         FW_Failure(FW_xMemoryExhausted);
  104.  
  105.     return aBlock;
  106. }
  107.  
  108. #ifdef FW_BUILD_MAC
  109. #pragma segment FWMemMgr2
  110. #endif
  111.  
  112. //----------------------------------------------------------------------------------------
  113. // FW_CMemoryManager::ResizeBlock - Resize a non-relocatable block of fMemory.  The
  114. //    block may be moved to a new location if necessary.
  115. //----------------------------------------------------------------------------------------
  116. void *FW_CMemoryManager::ResizeBlock(void *aBlock, unsigned long bytesRequested)
  117. {
  118.     void *newBlock = FW_PrivMemoryManager_ResizeBlock(aBlock, bytesRequested);
  119.  
  120.     if (newBlock == 0)
  121.         FW_Failure(FW_xMemoryExhausted);
  122.     
  123.     return newBlock;
  124. }
  125.  
  126. //----------------------------------------------------------------------------------------
  127. // FW_CMemoryManager::AllocateSystemHandle - 
  128. //----------------------------------------------------------------------------------------
  129. FW_PlatformHandle FW_CMemoryManager::AllocateSystemHandle(unsigned long bytesNeeded)
  130. {
  131.     FW_PlatformHandle aSystemHandle = FW_PrivMemoryManager_AllocateSystemHandle(bytesNeeded);
  132.     
  133.     if (aSystemHandle == 0)
  134.         FW_Failure(FW_xMemoryExhausted);
  135.  
  136.     return aSystemHandle;
  137. }
  138.  
  139. #ifdef FW_BUILD_MAC
  140. #pragma segment FWMemMgr3
  141. #endif
  142.  
  143. //----------------------------------------------------------------------------------------
  144. // FW_CMemoryManager::ResizeSystemHandle - 
  145. //----------------------------------------------------------------------------------------
  146. FW_PlatformHandle FW_CMemoryManager::ResizeSystemHandle(FW_PlatformHandle aHandle,
  147.                                                         unsigned long bytesNeeded)
  148. {
  149.     FW_ASSERT(aHandle != 0);
  150.  
  151.     FW_PlatformHandle newHandle = FW_PrivMemoryManager_ResizeSystemHandle(aHandle, bytesNeeded);
  152.  
  153.     if (newHandle == 0)
  154.         FW_Failure(FW_xMemoryExhausted);
  155.  
  156.     return newHandle;
  157. }
  158.  
  159. #ifdef FW_BUILD_MAC
  160. #pragma segment FWMemMgr4
  161. #endif
  162.  
  163. //----------------------------------------------------------------------------------------
  164. // FW_CMemoryManager::LockSystemHandle - 
  165. //----------------------------------------------------------------------------------------
  166. void * FW_CMemoryManager::LockSystemHandle(FW_PlatformHandle aHandle)
  167. {
  168.     FW_ASSERT(aHandle != 0);
  169.  
  170.     void* memory = FW_PrivMemoryManager_LockSystemHandle(aHandle);
  171.     
  172.     if (memory == NULL)
  173.         FW_Failure(FW_xMemoryExhausted);
  174.         
  175.     return memory;
  176. }
  177.  
  178. #ifdef FW_BUILD_MAC
  179. #pragma segment FWMemMgr6
  180. #endif
  181.  
  182. //----------------------------------------------------------------------------------------
  183. // FW_CMemoryManager::CopySystemHandle - 
  184. //----------------------------------------------------------------------------------------
  185. FW_PlatformHandle FW_CMemoryManager::CopySystemHandle(FW_PlatformHandle aHandle)
  186. {
  187.     FW_PlatformHandle newHandle = FW_PrivMemoryManager_CopySystemHandle(aHandle);
  188.     
  189.     if (newHandle == 0)
  190.         FW_Failure(FW_xMemoryExhausted);
  191.  
  192.     return newHandle;
  193. }
  194.  
  195. #ifdef FW_BUILD_MAC
  196. #pragma segment FWMemMgr7
  197. #endif
  198.  
  199.